package com.study.services;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.study.model.jdao.ICusmshfitDAO;
import com.study.model.jdao.ICustomerDAO;
import com.study.model.jdao.IDictionaryDAO;
import com.study.model.jdao.IUserDAO;
import com.study.model.mdao.CusmshfitMapper;
import com.study.model.pojo.Cusmshift;
import com.study.model.pojo.Customer;
import com.study.model.pojo.Dictionary;
import com.study.model.pojo.User;

/**
 * 客户共享
 * @author wjl
 *
 */
@Service
public class CusmshfitServices {
	@Autowired
	ICusmshfitDAO cusmse;
	@Autowired
	CusmshfitMapper mapper;
	@Autowired
	IUserDAO user;
	@Autowired
	ICustomerDAO cust;
	@Autowired
	IDictionaryDAO dict;
	@Autowired
	CusmshfitMapper cusmshfitmapper;

	/**
	 * 添加客户分享记录
	 * @param cusm 添加分享记录人id
	 * @param usersid  原客户所有人id
	 * @param cusid 分享用户人id
	 * @param cusids2  被分享的客户id
	 * @param desc  分享人所拥有的权限 可读 、可写、可读可写
	 * @return 
	 * @return
	 */
	public int addCusm(Integer cusm, Integer usersid, Integer cusid, Integer cusids2, String desc) {
		int insertCustcosition = mapper.insertCustcosition(cusm, usersid, cusid, cusids2,new Date(),desc);
		return insertCustcosition;
	}

	/**
	 * 修改分享记录
	 * @param cusm
	 * @param usersid
	 * @param cusid
	 * @param cusids2
	 * @param desc
	 */
	public void updateCusm(Integer cusm, Integer usersid, Integer cusid, Integer cusids2, String desc) {
		mapper.updateCusmshifID(cusm, usersid, cusid, cusids2,new Date(),desc);
		System.out.println(new Date());
	}
	
	
	/**
	 * 查找所有的共享记录
	 * @return 
	 * @return 
	 */
	public List<JSONObject> getfindCustmoer(){
		
		return cusmshfitmapper.selectCusmshiftAll();
	}
	
	public List<JSONObject> cusmshfitIDall(Integer usersid, Integer cusid, Integer cusids2) {
		return cusmshfitmapper.selectCusmshifIDAll(usersid, cusid,cusids2);
	}
	public int delectCushfitById(int xm) {
		return cusmshfitmapper.delectCusmshfitId(xm);
	}
	
	/**
	 * 分页查询
	 */
	public List<JSONObject> selectByPagerse(int pageNum, int pageSize,String name,int useid) {
		// 配置分页信息。这句话后面的第一个查询将调用分页。使用分页，对应的Service方法最好只写一个查询方法
		PageHelper.startPage(pageNum, pageSize);
		// 获取
		//List<JSONObject> list = cusmshfitmapper.selectCusmshiftAll();
		String input = "%"+name+"%";
		List<JSONObject> list=cusmshfitmapper.selectCusmshiftAllWhere(input,useid);
		System.out.println("大小" + list.size());
		return list;
	}

}
